/**
 * =================================================================
 * 版权所有 2011-2013 深圳市泰海网络科技服务有限公司，并保留所有权利
 * -----------------------------------------------------------------
 * 这不是一个自由软件！您不能在任何未经允许的前提下对程序代码进行修改和使用；
 * 不允许对程序代码以任何形式任何目的的再发布
 * =================================================================
 */
package com.imoney.payment.web.utils;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.context.request.WebRequest;

/**
 * 类说明：<br>
 * 
 * <p>
 * 详细描述：<br>
 * 
 * </p>
 * 
 * <pre>
 * ——————————————————————————————————————————————————————————————————
 * |		修改人		|		修改时间			|		修改原因
 * ——————————————————————————————————————————————————————————————————
 * |	zengxx 曾宪新	|		2013-3-27		|	
 * ——————————————————————————————————————————————————————————————————
 * </pre>
 * 
 * @author zengxx 曾宪新(Xavier.zeng)
 * 
 *         CreateDate: 2013-3-27
 */
public class WebUtil {

	public static boolean isAjaxRequest(WebRequest webRequest) {
		String requestedWith = webRequest.getHeader("X-Requested-With");
		if (null == requestedWith) {
			return false;
		}

		return "XMLHttpRequest".equals(requestedWith);
	}

	public static boolean isAjaxUploadRequest(WebRequest webRequest) {
		return null != webRequest.getParameter("ajaxUpload");
	}
	
	/**
	 * 方法说明：获取用户IP
	 * 
	 * @param request
	 * @return
	 */
	public static String getIpAdrr(HttpServletRequest request) {
		String ip = request.getHeader("x-forwarded-for");
		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
			ip = request.getHeader("Proxy-Client-IP");
		}
		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
			ip = request.getHeader("WL-Proxy-Client-IP");
		}
		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
			ip = request.getRemoteAddr();
		}
		return ip;
	}

	/**
	 * 方法说明：<br>
	 * 
	 * @param request获得SESSION属性
	 * @param name
	 * @return
	 */
	public static Object getSession(HttpServletRequest request, String name) {
		return request.getSession().getAttribute(name);
	}

	/**
	 * 方法说明：<br>
	 * 
	 * @param str
	 * @return
	 */
	public static boolean isInvalidChar(String str) {
		
		return false;
	}
}
